#include "wh_lte_driver.h"
#include <string.h>

static bool bModelStartup = false;

static bool bModelConfigDone = false;

static uint8_t u8Model4GBuff[MODEL_BUFF_SIZE] = {0x0};
static uint32_t u32Model4GBuffFilledLength = 0;
//串口发送接口
static uart_snd snd_port = NULL;

static osMessageQId g_Model4GControlMsgQueue;
static osMessageQDef(g_Model4GControlMsgQueue, 5, uint32_t);

void InitModelDriver(void)
{
	g_Model4GControlMsgQueue = osMessageCreate(osMessageQ(g_Model4GControlMsgQueue), NULL);
}

osMessageQId getModel4GControlMsgQueneID(void)
{
	return g_Model4GControlMsgQueue;
}

void setModelStartupStatus(bool bStartDone)
{
	bModelStartup = bStartDone;
}

bool getModelStartupDone(void)
{
	return bModelStartup;
}

void setModelConfigStatus(bool cfgDone)
{
	bModelConfigDone = cfgDone;
}

bool getModelConfigStatus(void)
{
	return bModelConfigDone;
}

void setModel4GBuff(uint8_t *data, uint32_t length)
{
	memcpy((void *)u8Model4GBuff, (const char *)data, length);
	u32Model4GBuffFilledLength = length;
}

uint32_t getModel4GBuffFilledLength(void)
{
	return u32Model4GBuffFilledLength;
}

uint8_t* getModel4GBuff(void)
{
	return u8Model4GBuff;
}

//设置串口发送接口
void setUartSendPort(uart_snd snd_uart)
{
	snd_port = snd_uart;
}

//检查模块是否启动完毕
bool checkModelStartupStatus(const char *in)
{
	if(strncmp((const char *)in, MODEL_TYPE, strlen(MODEL_TYPE)) == 0)
		return true;
	else
		return false;
}

//设置模块进入命令状态
void setModelEnterCmdStatus(bool bCmdMode, uint32_t bStep)
{
	if(bStep == 0)
	{
		if(bCmdMode)
			snd_port(MODEL_ENTER_CMD_CMD, strlen(MODEL_ENTER_CMD_CMD));
		else
			snd_port(MODEL_ENTER_BYPS_CMD, strlen(MODEL_ENTER_BYPS_CMD));
	}
	else
		snd_port("a", 1);
}

void setModelEchoStatus(bool bEchoOn)
{
	if(bEchoOn)
		snd_port(MODEL_ECHO_SET_CMD"on\r\n", strlen(MODEL_ECHO_SET_CMD) + 4);
	else
		snd_port(MODEL_ECHO_SET_CMD"off\r\n", strlen(MODEL_ECHO_SET_CMD) + 5);
}

void setSockB(void)
{
	snd_port(MODEL_SETSOCKB_TCP_LONGCNT, strlen(MODEL_SETSOCKB_TCP_LONGCNT));
}

